package com.pactera.miyuangroup.controller.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.pactera.miyuangroup.db.entity.GoodsClassification;
import com.pactera.miyuangroup.service.GoodsClassificationService;
import com.pactera.miyuangroup.service.GoodsInfoService;
import com.pactera.miyuangroup.vo.convertor.GoodsClassificationConvert;
import com.pactera.miyuangroup.vo.request.VoidRequest;
import com.pactera.miyuangroup.vo.request.web.GoodsInfoReques;
import com.pactera.miyuangroup.vo.response.ResultModel;
import com.pactera.miyuangroup.vo.response.ResultStatusCode;
import com.pactera.miyuangroup.vo.response.VoidResponse;
import com.pactera.miyuangroup.vo.response.app.AppClassificationRes;
import com.pactera.miyuangroup.vo.response.web.GoodsInfoRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述:
 *
 * @outhor 张汉卿
 * @create 2018-04-25 16:50
 */
@Api(description = "商品信息")
@RestController
@RequestMapping("GoodsInfo")
@Slf4j
public class GoodsInfoController {

    @Autowired
    private GoodsClassificationService goodsClassificationService;
    @Autowired
    private GoodsClassificationConvert goodsClassificationConvert;

    @Autowired
    private GoodsInfoService goodsInfoService;

    @ApiOperation(value = "商品信息列表", notes = "商品信息列表")
    @RequestMapping(value = "/getGoodsInfoList", method = RequestMethod.POST)
    private ResultModel<Page<GoodsInfoRes>> getGoodsInfoList(@RequestBody GoodsInfoReques goodsInfoReques) {
        Page<GoodsInfoRes> GoodsInfoList = goodsInfoService.getGoodsInfoList(goodsInfoReques);
        return ResultModel.ok(GoodsInfoList);
    }


    @ApiOperation(value = "商品分类查询", notes = "商品分类查询")
    @RequestMapping(value = "/classification", method = RequestMethod.GET)
    public ResultModel<List<AppClassificationRes>> selectVendorGoodsClassificationList() {
        List<GoodsClassification> list = goodsClassificationService.selectList(null);
        return ResultModel.ok(goodsClassificationConvert.convert2ClassificationResList(list));
    }

    @ApiOperation(value = "同步商品", notes = "同步商品")
    @RequestMapping(value = "/syncGoodsInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncGoodsInfos() {
        boolean flg = goodsInfoService.syncGoodsInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步商品分类", notes = "同步商品分类")
    @RequestMapping(value = "/syncGoodsInfoClassificationInfos", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncGoodsClassificationInfos() {
        boolean flg = goodsClassificationService.syncMiyuanGoodsClassificationInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }
}
